package com.lavegue.webaction;

import com.lavegue.common.Constants;
import com.lavegue.common.ListAction;
import com.lavegue.model.BisGroup;
import com.lavegue.model.Company;
import com.lavegue.service.CompanyService;


/**
 * author: tinazhifen
 * description:
 *
 */
public class CompanyAction extends ListAction<Company> {
	private CompanyService companyService;
	private String panyName;//公司名称
	private int panyId;
	private Company upCompany;
	private String upanyName;
	
	//根据公司名称列出所有的公司
	public String allCompanyListByName()
	{
		 if(null==this.getSessionAtrribute(Constants.MAN_SESSION_USER))
		   {
			   return "lg";
		   }
		pageObj=companyService.getAllCompanyByName(pageNo, pageSize,null);
		return "listComp";
	}
		
	
	//删除公司
	public String delCompany()
	{
		Company delCom=companyService.findById(panyId);
	    try {
			if (delCom != null) {
				companyService.deleteById(panyId);
			}
		} catch (Exception e) {
			
			this.addActionError("该公司已被使用,请先取消使用");
		}
		return allCompanyListByName();
	}
	
	

    //更新公司
	public String updateCompany()
	{
	     Company upCom=companyService.findById(panyId);
	     upCom.setCompanyName(upanyName);
	     companyService.update(upCom);
		return allCompanyListByName();
	}
	
	//新增加公司
	public String addCompany()
	{
		Company addCom=new Company();
		addCom.setCompanyName(panyName);
		companyService.save(addCom);
		return allCompanyListByName();
	}


	public CompanyService getCompanyService() {
		return companyService;
	}


	public void setCompanyService(CompanyService companyService) {
		this.companyService = companyService;
	}


	public String getPanyName() {
		return panyName;
	}


	public void setPanyName(String panyName) {
		this.panyName = panyName;
	}


	public int getPanyId() {
		return panyId;
	}


	public void setPanyId(int panyId) {
		this.panyId = panyId;
	}


	public Company getUpCompany() {
		return upCompany;
	}


	public void setUpCompany(Company upCompany) {
		this.upCompany = upCompany;
	}


	public String getUpanyName() {
		return upanyName;
	}


	public void setUpanyName(String upanyName) {
		this.upanyName = upanyName;
	}
	
	
	
	
}

